//1. 导入模块

const httpp = require('http');
const fs = require('fs');
const path = require('path');

var url = require('url'); //已废弃
// 2. 创建WEB服务器实力
const serve = httpp.createServer(() => {

});

//当有人请求时，会打印信息
serve.on('request', function(req, res) {
    const myUrl = new URL(req.url, 'http://127.0.0.1:3000')
    console.log(myUrl);
    // console.log(myUrl.searchParams.getAll('name'));
    myUrl.searchParams.forEach((value, name, searchParams) => {

        console.log(1);
        console.log(name, value, myUrl.searchParams === searchParams);
    });

    // Url {
    //     protocol: null,
    //     slashes: null,
    //     auth: null,
    //     host: null,
    //     port: null,
    //     hostname: null,
    //     hash: null,
    //     search: null,
    //     query: null,
    //     pathname: '/api/list',
    //     path: '/api/list',
    //     href: '/api/list'
    //   }
    // fs.readFile(path.join(__dirname, './clock/index.html'), 'utf-8', function(err, data) {
    //     res.end(data)
    // })


});

serve.listen(3000, function() {
    console.log('server running at http://127.0.0.1:3000');
});